package org.rich.charlesmurphy.core.analyze;

import java.util.ArrayList;
import java.util.List;

import org.ddevil.data.Filter;
import org.rich.charlesmurphy.core.BaseObject;
import org.rich.charlesmurphy.model.Request;

/**
 * Base class for anal yzers.
 * @author Rich
 */
public abstract class AbstractAnalyzer extends BaseObject implements RequestSetAnalyzer {

	private List<Filter<Request>> filters = new ArrayList<Filter<Request>>();

	public RequestSetAnalyzer addFilter(Filter<Request> filter) {
		filters.add(filter);
		return this;
	}

	/**
	 * Check all filters to see if the given request should be accepted.
	 * @param r request
	 * @return <code>true</code> if all filters accept.
	 */
	protected boolean accept(Request r) {
		for (Filter<Request> f : filters) {
			if (!f.accept(r)) {
				getLog().trace("Filtering out request: [{}]", r);
				return false;
			}
		}
		return true;
	}

	/**
	 * @return the filter list.
	 */
	protected List<Filter<Request>> getFilters() {
		return filters;
	}
}
